﻿using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security.AntiXss;

namespace LanguageFeatures.Models
{
    public class MyAsyncMethods
    {
        /// <summary>
        /// 使用async方法进行异步查询
        /// 请求http://www.z01.com主页的内容并返回它的长度
        /// </summary>
        /// <returns></returns>
        public static Task<long?> GetPageLength()
        {
            HttpClient client = new HttpClient();
            var httpTask = client.GetAsync("http://www.z01.com");
            //在等待http请求完成期间，此处可以做其它事情
            return httpTask.ContinueWith((Task<HttpResponseMessage> antecedent) =>
            {
                return antecedent.Result.Content.Headers.ContentLength;
            });
        }
    }
}